/*
* Copyright (c) 2014 Qunar.com. All Rights Reserved.
*/
package net.oschina.bilbodai.common.beanutil.property.asm.lexer.code;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

import java.util.LinkedList;
import java.util.List;

/**
 * 包含数组或者List的解析
 *
 * @author qt-maodai  Date: 15-8-5 Time: 下午10:56
 * @version $Id$
 */
public class ListCodeApplier extends BaseCodeApplier {

    private final int index;
    private final Class<?> valueType;

    public ListCodeApplier(CodeApply codeApply, int index, Class<?> valueType) {
        super(codeApply);
        this.index = index;
        this.valueType = valueType;
    }

    @Override
    protected CodeApplyResult applyCode(MethodVisitor mv, CodeApply codeApply) throws Exception {
        mv.visitIntInsn(Opcodes.BIPUSH, getIndex());
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(List.class), "get", "(I)Ljava/lang/Object;", true);
        return new CodeApplyResult(valueType, Object.class, new LinkedList<Class<?>>());
    }

    public int getIndex() {
        return index;
    }

}